<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    手机号码：<input type="number"><button>发送验证码</button>
    <script>
        /* 
        需求：
            1. 点击按钮，开启倒计时。按钮禁用
            2.倒计时结束，按钮恢复
        */

        var btn = document.querySelector('button');

        btn.addEventListener('click', () => {
            var index = 3; // 计数器
            btn.innerHTML = index;
            btn.disabled = true;

            var timer = setInterval(function () {
                console.log('点击了');
                index--;
                btn.innerHTML = index;

                if (index == 0) {
                    btn.disabled = false;
                    btn.innerHTML = '发送验证码 ';
                    clearInterval(timer);
                }
            }, 1000);
        })
    </script>
</body>

</html>